<?php
/**
 * Created by EditPlus.
 * User: GRAY <iamgray@gmail.com>
 * Date: 8/4/16
 * Time: 19:43
 */

namespace Home\Controller;

use Common\Library\BusinessException;
use Common\Library\Constant;
use Think\Controller;
use Common\Library\Http\Request;
use Common\Library\Http\Response;
use Think\Log;
use Common\Vendor\Hook\BaseHook;


class CrawlerPostController extends Controller {

    protected $request_url = 'https://collect.hulushuju.com';
    //protected $request_url = 'http://222.73.159.209:9090';

    public function __construct() {
        parent::__construct();

        try {
            Request::parse();
        } catch (BusinessException $e) {
            $this->ajaxReturn(['code' => $e->getCode(), 'msg' => $e->getMessage()]);
        }
    }
/*
    // 获取token
    public function getToken() {
        $url = 'http://222.73.159.209:9090/crawler/applications/payment/alipay';
        $xml_data = array(
            "company_account"=> "xxxxx",
            "name"=> "张华",
            "identity_card_number"=> "120107197710304519",
            "cell_phone_number"=> "15510947909",
        );
        $xml_data = json_encode($xml_data);
        print_r($this->curlPost($url,$xml_data));

    }
    //登录采集
    public function getToken1() {
        $url = 'http://222.73.159.209:9090/crawler/authorize/payment/alipay/collect/';
        $xml_data = array(
            "token"=>"68ed0f778f73416b832c00e9904f72a1",
            "account"=>"koudai@heshuibar.com",
            "password"=>"hsb123456"
        );
        $xml_data = json_encode($xml_data);
        print_r($this->curlPost($url,$xml_data));

    }


    public function getToken1() {
        $url = $this->request_url.'/api/applications/mobile';
        $xml_data = array(
            "company_account"=> "xxxxx",
            "name"=> "王鹏飞",
            "identity_card_number"=> "142729199412083610",
            "cell_phone_number"=> "18634364997",
        );
        $xml_data = json_encode($xml_data);
        print_r($this->curlPost($url,$xml_data));
    }
*/
    //登录采集
    public function mobileCollect() {
        try{
            $mobile = I('post.mobile', '', 'string');
            $password = I('post.password', '', 'string');
            $captcha = I('post.captcha', '', 'string');
            $query_password = I('post.query_password', '', 'string');
            $token = I('post.token', '', 'string');
            $type = I('post.type', 1, 'int');

            $CustomerInfo = M('Customer')->where(['mobile' => $mobile])->find();
            $name = $CustomerInfo['real_name'];
            $id_num = $CustomerInfo['id_num'];
            $CustomerID = $CustomerInfo['id'];

            if (!$name || !$id_num || !$mobile) {
                BusinessException::throwException('请用本人注册的手机号认证');
            }
            if($type ==2 ) {
                sleep(5);
                M('CustomerAuth')->where(['customer_id'=>$CustomerID])->setField(['china_mobile'=>1,'password'=>$password,'flag'=>2]);
                $ret = Constant::getReturn(Constant::SUCCESS);
                Response::format($ret);
                $this->ajaxReturn($ret);
            }
            if($token=='') {
                $url = $this->request_url.'/api/applications/mobile';
                $xml_data = array(
                    "company_account"=> "xxxxxxx",
                    "name"=> $name,
                    "identity_card_number"=> $id_num,
                    "cell_phone_number"=> $mobile,
                );
                $xml_data = json_encode($xml_data);
                $token = '';
                $return_data = json_decode($this->curlPost($url,$xml_data),true);
                if($return_data) {
                    if($return_data['code']==8209) {
                        $token = $return_data['data']['token'];
                    } else {
                        BusinessException::throwException($return_data['message']);
                    }
                } else {
                    BusinessException::throwException('获取token失败');
                }
            }
            
            if($token<>'') {
                $url = $this->request_url.'/api/authorize/mobile/collect';
                if($password<>'') {
                    $xml_data = array(
                        "token"=>$token,
                        "password"=>$password
                    );
                    M('CustomerAuth')->where(['customer_id'=>$CustomerID])->setField(['password'=>$password]);
                }
                if($captcha<>'') {
                    $xml_data = array(
                        "token"=>$token,
                        "captcha"=>$captcha
                    );
                }
                if($query_password<>'') {
                    $xml_data = array(
                        "token"=>$token,
                        "query_password"=>$query_password
                    );
                }
                $xml_data = json_encode($xml_data);
                $return_data = json_decode($this->curlPost($url,$xml_data),true);
                if($return_data) {
                    if($return_data['code']==12291) {
                        //数据源授权成功,流程结束 COLLECT_DATASOURCE_AUTHORIZED_SUCCESS
                        //echo $return_data1['code_description'];
                        M('CustomerAuth')->where(['customer_id'=>$CustomerID])->setField(['china_mobile'=>1,'token'=>$token,'password'=>$password]);
                        $ret = Constant::getReturn(Constant::SUCCESS);
                    } elseif($return_data['code']==12800) {
                        //输入查询详单短信验证码 COLLECT_CAPTCHA_REQUIRED 采集接口以及采集重新发送验证码接口返回,用户输入短信验证码,再次调用采集接口完成认证
                        $ret = array('code'=>12800,'msg'=>'输入查询详单短信验证码');
                        $ret['data'] = array('token'=>$token);
                    } elseif($return_data['code']==12808) {
                        //输入登陆短信验证码 COLLECT_LOGIN_CAPTCHA_REQUIRED 采集接口会返回输入登陆的短信验证码,目前有辽宁移动和吉林移动,后面还需提交查询详单短信验证码
                        $ret = array('code'=>12808,'msg'=>'输入登陆短信验证码');
                        $ret['data'] = array('token'=>$token);
                    } elseif($return_data['code']==13824) {
                        //输入查询密码 COLLECT_QUERY_PASSWORD_REQUIRED 北京移动会出现输入查询密码或短信验证码
                        $ret = array('code'=>13824,'msg'=>'输入查询密码');
                        $ret['data'] = array('token'=>$token);
                    } else {
                        BusinessException::throwException($return_data['message']);
                    }
                } else {
                    BusinessException::throwException('认证请求失败');
                }
            } else {
                BusinessException::throwException('获取token失败');
            }
        } catch (BusinessException $e){
            //$ret = ['code'=>$e->getCode(), 'msg'=>$e->getMessage()];
            if($e->getMessage() == '请用本人注册的手机号认证') {
                $ret = ['code'=>10003, 'msg'=>$e->getMessage()];
            } elseif($e->getMessage() == '简单密码或初始密码无法登录') {
                $ret = ['code'=>10003, 'msg'=>$e->getMessage()];
            } elseif($e->getMessage() == '密码不正确') {
                $ret = ['code'=>10003, 'msg'=>$e->getMessage()];
            } else {
                $ret = ['code'=>$e->getMessage(), 'msg'=>'运营商网络拥堵，请业务员协助用运营商链接重新认证一次'];
            }
        }

        Response::format($ret);
        $this->ajaxReturn($ret);
    }


    //采集重发验证码
    public function collectResend() {
        try{
            $token = I('post.token', '', 'string');
            if (!$token) {
                BusinessException::throwException(Constant::INVALID_PARAMETER);
            }
            $url = $this->request_url.'/api/api/authorize/captcha/collect/resend';
            $xml_data = array(
                "token"=> $token,
            );
            $xml_data = json_encode($xml_data);
            $return_data = json_decode($this->curlPost($url,$xml_data),true);
            //print_r($return_data);
            if($return_data) {
                if($return_data['code']==12800) {
                    $ret = Constant::getReturn(Constant::SUCCESS);
                    $ret['data'] = array('token'=>$token);
                } else {
                    BusinessException::throwException('运营商网络拥堵，'.$return_data['code'].$return_data['message']);
                }
            } else {
                BusinessException::throwException('运营商网络拥堵，采集重发验证码失败');
            }
        } catch (BusinessException $e){
            $ret = ['code'=>$e->getCode(), 'msg'=>$e->getMessage()];
        }
        Response::format($ret);
        $this->ajaxReturn($ret);
    }


    //重置密码获取token （作废）
    public function getToken() {
        try{
            $mobile = I('post.mobile', '', 'string');

            $CustomerInfo = M('Customer')->where(['mobile' => $mobile])->find();
            $name = $CustomerInfo['real_name'];
            $id_num = $CustomerInfo['id_num'];

            if (!$name || !$id_num || !$mobile) {
                BusinessException::throwException(Constant::INVALID_PARAMETER);
            }

            $url = $this->request_url.'/api/applications/mobile';
            $xml_data = array(
                "company_account"=> "xxxxx",
                "name"=> $name,
                "identity_card_number"=> $id_num,
                "cell_phone_number"=> $mobile,
            );
            $xml_data = json_encode($xml_data);
            $token = '';
            $return_data = json_decode($this->curlPost($url,$xml_data),true);
            if($return_data) {
                if($return_data['code']==8209) {
                    $token = $return_data['data']['token'];
                    $ret = Constant::getReturn(Constant::SUCCESS);
                    $ret['data'] = array('token'=>$token);
                } else {
                    BusinessException::throwException($return_data['code'].$return_data['message']);
                }
            } else {
                BusinessException::throwException('获取token失败');
            }
        } catch (BusinessException $e){
            $ret = ['code'=>$e->getCode(), 'msg'=>$e->getMessage()];
        }
        Response::format($ret);
        $this->ajaxReturn($ret);
    }

    //重置密码发送验证码
    public function resetPasswordSend() {
        try{
            $mobile = I('post.mobile', '', 'string');
            $type = I('post.type', 1, 'int');

            $CustomerInfo = M('Customer')->where(['mobile' => $mobile])->find();
            $name = $CustomerInfo['real_name'];
            $id_num = $CustomerInfo['id_num'];

            if (!$name || !$id_num || !$mobile) {
                BusinessException::throwException(Constant::INVALID_PARAMETER);
            }

            $url = $this->request_url.'/api/applications/mobile';
            $xml_data = array(
                "company_account"=> "xxxxx",
                "name"=> $name,
                "identity_card_number"=> $id_num,
                "cell_phone_number"=> $mobile,
            );
            $xml_data = json_encode($xml_data);
            $token = '';
            $return_data = json_decode($this->curlPost($url,$xml_data),true);
            if($return_data) {
                if($return_data['code']==8209) {
                    $token = $return_data['data']['token'];
                } else {
                    BusinessException::throwException($return_data['code'].$return_data['message']);
                }
            } else {
                BusinessException::throwException('运营商网络拥堵，获取token失败');
            }

            if (!$token ) {
                BusinessException::throwException(Constant::INVALID_PARAMETER);
            }
            $url = $this->request_url.'/api/authorize/password/reset';
            if($type == 2) {
                $url = $this->request_url.'/api/authorize/captcha/reset/resend';
            }
            $xml_data = array(
                "token"=> $token,
            );
            $xml_data = json_encode($xml_data);
            $return_data = json_decode($this->curlPost($url,$xml_data),true);
            //print_r($return_data);
            if($return_data) {
                if($return_data['code']==13569) {
                    $ret = Constant::getReturn(Constant::SUCCESS);
                    $ret['data'] = array('token'=>$token);
                } else {
                    BusinessException::throwException($return_data['code'].$return_data['message'].'，请拨打运营商电话找回密码');
                }
            } else {
                BusinessException::throwException('运营商网络拥堵，发送验证码失败，请拨打运营商电话找回密码');
            }
        } catch (BusinessException $e){
            $ret = ['code'=>$e->getCode(), 'msg'=>$e->getMessage()];
        }
        Response::format($ret);
        $this->ajaxReturn($ret);
    }

    //重置密码重新发送验证码（作废）
    public function resetPasswordReSend() {
        try{
            $mobile = I('post.mobile', '', 'string');

            $CustomerInfo = M('Customer')->where(['mobile' => $mobile])->find();
            $name = $CustomerInfo['real_name'];
            $id_num = $CustomerInfo['id_num'];

            if (!$name || !$id_num || !$mobile) {
                BusinessException::throwException(Constant::INVALID_PARAMETER);
            }

            $url = $this->request_url.'/api/applications/mobile';
            $xml_data = array(
                "company_account"=> "xxxxx",
                "name"=> $name,
                "identity_card_number"=> $id_num,
                "cell_phone_number"=> $mobile,
            );
            $xml_data = json_encode($xml_data);
            $token = '';
            $return_data = json_decode($this->curlPost($url,$xml_data),true);
            if($return_data) {
                if($return_data['code']==8209) {
                    $token = $return_data['data']['token'];
                } else {
                    BusinessException::throwException($return_data['code'].$return_data['message']);
                }
            } else {
                BusinessException::throwException('获取token失败');
            }
            if (!$token ) {
                BusinessException::throwException(Constant::INVALID_PARAMETER);
            }
            $url = $this->request_url.'/api/authorize/captcha/reset/resend';
            $xml_data = array(
                "token"=> $token,
            );
            $xml_data = json_encode($xml_data);
            $return_data = json_decode($this->curlPost($url,$xml_data),true);
            //print_r($return_data);
            if($return_data) {
                if($return_data['code']==13569) {
                    $ret = Constant::getReturn(Constant::SUCCESS);
                    $ret['data'] = array('token'=>$token);
                } else {
                    BusinessException::throwException($return_data['code'].$return_data['message']);
                }
            } else {
                BusinessException::throwException('重发送验证码失败');
            }
        } catch (BusinessException $e){
            $ret = ['code'=>$e->getCode(), 'msg'=>$e->getMessage()];
        }
        Response::format($ret);
        $this->ajaxReturn($ret);
    }

    //重置密码
    public function resetPassword() {
        try{
            $token = I('post.token', '', 'string');
            $password = I('post.password', '', 'string');
            $captcha = I('post.captcha', '', 'string');
            if (!$token || !$password || !$captcha) {
                BusinessException::throwException(Constant::INVALID_PARAMETER);
            }
            $url = $this->request_url.'/api/authorize/password/reset';
            $xml_data = array(
                "token"=> $token,
                "password"=> $password,
                "captcha"=> $captcha,
            );
            $xml_data = json_encode($xml_data);
            $return_data = json_decode($this->curlPost($url,$xml_data),true);
            //print_r($return_data);
            if($return_data) {
                if($return_data['code']==13573) {
                    $ret = Constant::getReturn(Constant::SUCCESS);
                } else {
                    BusinessException::throwException($return_data['code'].$return_data['message'].'，请拨打运营商电话找回密码');
                }
            } else {
                BusinessException::throwException('运营商网络拥堵，重置密码失败，请拨打运营商电话找回密码');
            }
        } catch (BusinessException $e){
            $ret = ['code'=>$e->getCode(), 'msg'=>$e->getMessage()];
        }
        Response::format($ret);
        $this->ajaxReturn($ret);
    }

    //聚信立获取token（作废）
    public function getToken2() {
        try{
            $mobile = I('post.mobile', '', 'string');

            $CustomerInfo = M('Customer')->where(['mobile' => $mobile])->find();
            $name = $CustomerInfo['real_name'];
            $id_num = $CustomerInfo['id_num'];
            $uid = $CustomerInfo['id'];

            if (!$name || !$id_num || !$mobile) {
                BusinessException::throwException(Constant::INVALID_PARAMETER);
            }

            $url = 'https://www.juxinli.com/orgApi/rest/v3/applications/xxxxx';
            $xml_data = array(
                "selected_website"=>array(),
                "basic_info"=>array(
                    "name"=> $name,
                    "id_card_num"=> $id_num,
                    "cell_phone_num"=> $mobile,
                ),
                "skip_mobile"=>false,
                "uid"=> $uid,
            );
            $xml_data = json_encode($xml_data);
            $token = '';
            $return_data = json_decode($this->curlPost($url,$xml_data),true);
            if($return_data) {
                if($return_data['code']==65557) {
                    $token = $return_data['data']['token'];
                    $website= $return_data['data']['datasource']['website'];
                    $ret = Constant::getReturn(Constant::SUCCESS);
                    $ret['data'] = array('token'=>$token);
                } else {
                    BusinessException::throwException($return_data['code'].$return_data['message']);
                }
            } else {
                BusinessException::throwException('获取token失败');
            }
        } catch (BusinessException $e){
            $ret = ['code'=>$e->getCode(), 'msg'=>$e->getMessage()];
        }
        Response::format($ret);
        $this->ajaxReturn($ret);
    }

    //聚信立采集
    public function mobileCollect2() {
        try{
            $mobile = I('post.mobile', '', 'string');
            $password = I('post.password', '', 'string');

            $captcha = I('post.captcha', '', 'string');
            $query_password = I('post.query_password', '', 'string');
            $token = I('post.token', '', 'string');
            $website = I('post.website', '', 'string');


            $CustomerInfo = M('Customer')->where(['mobile' => $mobile])->find();
            $name = $CustomerInfo['real_name'];
            $id_num = $CustomerInfo['id_num'];
            $CustomerID = $CustomerInfo['id'];

            if (!$name || !$id_num || !$mobile) {
                //BusinessException::throwException(Constant::INVALID_PARAMETER);
                 BusinessException::throwException('请用本人注册的手机号认证');
            }

            if($token=='') {
                $url = 'https://www.juxinli.com/orgApi/rest/v3/applications/xxxxxxxxxxx';
                $xml_data = array(
                    "selected_website"=>array(),
                    "basic_info"=>array(
                        "name"=> $name,
                        "id_card_num"=> $id_num,
                        "cell_phone_num"=> $mobile,
                    ),
                    "skip_mobile"=>false,
                    "uid"=> $CustomerID,
                );
                $xml_data = json_encode($xml_data);
                $token = '';
                $website = '';
                $return_data = json_decode($this->curlPost($url,$xml_data),true);
                if($return_data) {
                    if($return_data['code']==65557) {
                        $token = $return_data['data']['token'];
                        $website= $return_data['data']['datasource']['website'];
                    } else {
                        BusinessException::throwException($return_data['code'].$return_data['message']);
                    }
                } else {
                    BusinessException::throwException('获取token失败');
                }
            }
            
            if($token<>'' && $website<>'') {
                $url = 'https://www.juxinli.com/orgApi/rest/v2/messages/collect/req';
                if($password<>'') {
                    $xml_data = array(
                        "token"=>$token,
                        "password"=>$password,
                        "account"=>$mobile,
                        "website"=>$website,
                        "captcha"=>"",
                        "type"=>"",
                    );
                    M('CustomerAuth')->where(['customer_id'=>$CustomerID])->setField(['password'=>$password]);
                }
                if($captcha<>'') {
                    $xml_data = array(
                        "token"=>$token,
                        "password"=>$password,
                        "account"=>$mobile,
                        "website"=>$website,
                        "captcha"=>$captcha,
                        "type"=>"SUBMIT_CAPTCHA",
                    );
                }
                if($query_password<>'') {
                    $xml_data = array(
                        "token"=>$token,
                        "password"=>$password,
                        "account"=>$mobile,
                        "website"=>$website,
                        "queryPwd"=>$query_password,
                        "type"=>"SUBMIT_QUERY_PWD",
                    );
                }
                $xml_data = json_encode($xml_data);
                $return_data = json_decode($this->curlPost($url,$xml_data),true);
                //print_r($return_data);
                if($return_data) {
                    if($return_data['data']['process_code']== 10008 && $return_data['success']== true) {
                        //抓取成功
                        //echo $return_data1['code_description'];
                        M('CustomerAuth')->where(['customer_id'=>$CustomerID])->setField(['china_mobile'=>1,'token2'=>$token,'password'=>$password]);
                        $ret = Constant::getReturn(Constant::SUCCESS);
                    } elseif($return_data['data']['process_code']== 10002 && $return_data['success']== true) {

                        $ret = array('code'=>100020,'msg'=>'输入短信验证码');
                        $ret['data'] = array('token'=>$token,'mobile'=>$mobile,'password'=>$password,'website'=>$website);

                    } elseif($return_data['data']['process_code']== 10001 && $return_data['success']== true) {

                        $ret = array('code'=>10001,'msg'=>'再次输入短信验证码');
                        $ret['data'] = array('token'=>$token,'mobile'=>$mobile,'password'=>$password,'website'=>$website);

                    } elseif($return_data['data']['process_code']== 10004 && $return_data['success']== true) {

                        $ret = array('code'=>10004,'msg'=>'短信验证码错误');
                        $ret['data'] = array('token'=>$token,'mobile'=>$mobile,'password'=>$password,'website'=>$website);

                    } elseif($return_data['data']['process_code']== 10006 && $return_data['success']== true) {

                        $ret = array('code'=>10006,'msg'=>'短信验证码失效系统已自动重新下发');
                        $ret['data'] = array('token'=>$token,'mobile'=>$mobile,'password'=>$password,'website'=>$website);

                    } elseif($return_data['data']['process_code']== 10022 && $return_data['success']== true) {

                        $ret = array('code'=>10022,'msg'=>'输入查询密码');
                        $ret['data'] = array('token'=>$token,'mobile'=>$mobile,'password'=>$password,'website'=>$website);

                    } else {
                        BusinessException::throwException($return_data['data']['process_code'].$return_data['data']['content']);
                    }
                } else {
                    BusinessException::throwException('认证请求失败');
                }
            } else {
                BusinessException::throwException('获取token失败');
            }
        } catch (BusinessException $e){
            //$ret = ['code'=>$e->getCode(), 'msg'=>$e->getMessage()];
            if($e->getMessage() == '请用本人注册的手机号认证') {
                $ret = ['code'=>$e->getCode(), 'msg'=>$e->getMessage()];
            } elseif($e->getMessage() == '简单密码或初始密码无法登录') {
                $ret = ['code'=>$e->getCode(), 'msg'=>$e->getMessage()];
            } elseif($e->getMessage() == '密码错误') {
                $ret = ['code'=>$e->getCode(), 'msg'=>$e->getMessage()];
            } else {
                $ret = ['code'=>$e->getCode(), 'msg'=>'运营商网络拥堵，请业务员协助用运营商链接重新认证一次'];
            }
        }

        Response::format($ret);
        $this->ajaxReturn($ret);
    }

    //聚信立找回密码发送验证码
    public function resetPasswordSend2() {
        try{
            $mobile = I('post.mobile', '', 'string');

            $CustomerInfo = M('Customer')->where(['mobile' => $mobile])->find();
            $name = $CustomerInfo['real_name'];
            $id_num = $CustomerInfo['id_num'];
            $uid = $CustomerInfo['id'];

            if (!$name || !$id_num || !$mobile) {
                BusinessException::throwException(Constant::INVALID_PARAMETER);
            }

            $url = 'https://www.juxinli.com/orgApi/rest/v3/applications/xxxxx';
            $xml_data = array(
                "selected_website"=>array(),
                "basic_info"=>array(
                    "name"=> $name,
                    "id_card_num"=> $id_num,
                    "cell_phone_num"=> $mobile,
                ),
                "skip_mobile"=>false,
                "uid"=> $uid,
            );
            $xml_data = json_encode($xml_data);
            $token = '';
            $website = '';
            $return_data = json_decode($this->curlPost($url,$xml_data),true);
            if($return_data) {
                if($return_data['code']==65557) {
                    $token = $return_data['data']['token'];
                    $website= $return_data['data']['datasource']['website'];
                } else {
                    BusinessException::throwException($return_data['code'].$return_data['message']);
                }
            } else {
                BusinessException::throwException('获取token失败');
            }
            
            if($token<>'' && $website<>'') {
                $url = 'https://www.juxinli.com/orgApi/rest/v2/messages/reset/req';
                $xml_data = array(
                    "token"=>$token,
                    "password"=>'',
                    "account"=>$mobile,
                    "website"=>$website,
                    "captcha"=>"",
                    "type"=>"RESEND_RESET_PWD_CAPTCHA",
                );
                $xml_data = json_encode($xml_data);
                $return_data = json_decode($this->curlPost($url,$xml_data),true);
                //print_r($return_data);
                if($return_data) {
                    if($return_data['data']['process_code']== 10002 && $return_data['success']== true) {
                        //抓取成功
                        //echo $return_data1['code_description'];
                        $ret = Constant::getReturn(Constant::SUCCESS);
                        $ret['data'] = array('token'=>$token,'website'=>$website);
                    } else {
                        BusinessException::throwException($return_data['data']['process_code'].$return_data['data']['content']);
                    }
                } else {
                    BusinessException::throwException('获取验证码失败');
                }
            } else {
                BusinessException::throwException('获取token失败');
            }
        } catch (BusinessException $e){
            $ret = ['code'=>$e->getCode(), 'msg'=>$e->getMessage()];
        }

        Response::format($ret);
        $this->ajaxReturn($ret);
    }

    //聚信找回密码
    public function resetPassword2() {
        try{
            $token = I('post.token', '', 'string');
            $website = I('post.website', '', 'string');
            $password = I('post.password', '', 'string');
            $captcha = I('post.captcha', '', 'string');
            
            if($token<>'' && $website<>'') {
                $url = 'https://www.juxinli.com/orgApi/rest/v2/messages/reset/req';
                $xml_data = array(
                    "token"=>$token,
                    "password"=>$password,
                    "account"=>$mobile,
                    "website"=>$website,
                    "captcha"=>$captcha,
                    "type"=>"SUBMIT_RESET_PWD",
                );
                $xml_data = json_encode($xml_data);
                $return_data = json_decode($this->curlPost($url,$xml_data),true);
                //print_r($return_data);
                if($return_data) {
                    if($return_data['data']['process_code']== 11000 && $return_data['success']== true) {
                        //抓取成功
                        //echo $return_data1['code_description'];
                        $ret = Constant::getReturn(Constant::SUCCESS);
                    } else {
                        BusinessException::throwException($return_data['data']['process_code'].$return_data['data']['content']);
                    }
                } else {
                    BusinessException::throwException('找回密码请求失败');
                }
            } else {
                BusinessException::throwException('获取token失败');
            }
        } catch (BusinessException $e){
            $ret = ['code'=>$e->getCode(), 'msg'=>$e->getMessage()];
        }

        Response::format($ret);
        $this->ajaxReturn($ret);
    }

    function curlPost($url,$xml_data) {
        $ch=curl_init($url); 
        $header[] = "Content-type: application/json;charset=UTF-8";
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_TIMEOUT, 200);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 200);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        //curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
        //curl_setopt($ch, CURLOPT_NOSIGNAL, 1);

        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_data);
        $response = curl_exec($ch);
        if(curl_errno($ch))
        {
            print curl_error($ch);
        }
        curl_close($ch);
        return $response;
    }


/**********************
     * 抓取
     ***********************/
    function request_post($url = '', $param = '') {
        if (empty($url) || empty($param)) {
            return false;
        }

        $postUrl = $url;
        $curlPost = $param;
        $ch = curl_init();//初始化curl
        curl_setopt($ch, CURLOPT_URL,$postUrl);//抓取指定网页
        curl_setopt($ch, CURLOPT_HEADER, 0);//设置header
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上
        curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
        curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
        $data = curl_exec($ch);//运行curl
        curl_close($ch);

        return $data;
    }
   /*************
    * 获取13位微妙时间戳
    *************/
    function getMillisecond() {
        list($t1, $t2) = explode(' ', microtime());
        $time = sprintf('%.0f',(floatval($t1)+floatval($t2))*1000);
        return (string)$time;
    }
    /***********
     * 处理数据参数
     ************/
    function postData($post_data){
        $p_data['appId'] = Constant::LKB_APPID;
        //$p_data['appId'] = '';
        $p_data['timeunit'] = $this->getMillisecond();
        $p_data['token'] = md5("timeunit=" . $p_data['timeunit'] . "appkey=" . Constant::LKB_APPKEY);
        $p_data['userId'] = $post_data['userId'];
        Log::write("userID：".$p_data['userId'],Log::DEBUG);
        $post_data = array_merge($p_data,$post_data);
        $o = "";
        foreach ( $post_data as $k => $v )
        {
            $o.= "$k=" . urlencode( $v ). "&" ;
        }
        $p_data = substr($o,0,-1);
        return  $p_data;
    }
    //量化派网站建立一个用户的基本信息（增加或者更新）
    function saveUserLKB($post_data){
            $p_data = $this->postData($post_data);
            $url = "http://openapi.quantgroup.cn/LKBClient/openapi/saveUserInfo.json";
            $res = json_decode($this->request_post($url, $p_data));
            Log::write("导入信息结果：".$this->request_post($url, $p_data),Log::DEBUG);
            return $res;
    }

   /******************
    * 量化派用户授权1
    ******************/
     function  mandateUser1($init='',$is_use='')
     {
         try {
             $phone = I('post.mobile', '', 'string');
             $server_pass = I("post.server_pass", '', 'string');//服务密码
             $is_init = $init==0 ? $init:I('post.is_init','', 'string');

             Log::write("上行参数:".$phone.','.$server_pass.','.$is_init,Log::NOTICE);
             if (!$phone) {
                 BusinessException::throwException(Constant::INVALID_PARAMETER);
             }
             if ($is_init == 0) {
                 $customerInfo = M('Customer')->where(['mobile' => $phone])->find();
                 Log::write("用户信息：" . json_encode($customerInfo), Log::NOTICE);

                 if (!$customerInfo['id']) {//消费者不存在
                     BusinessException::throwException(Constant::CUSTOMER_NOT_FOUND);
                 }
                 if (session('LKB_index')) {
                     $index = session('LKB_index');
                 } else{
                     $index = 1;
                     session('LKB_index', $index);
                 }
                 $is_mandate = M("CustomerAuth")->where("customer_id =" . $customerInfo['id'])->find();
                 Log::write("认证是否：".json_encode($is_mandate),Log::NOTICE);
                if (empty($is_mandate)){
                    BusinessException::throwException(Constant::ID_NUM_NO_AUTHED);
                 }
                 if (!empty($is_mandate) && $is_mandate['china_mobile'] == 0) {//未进行认证
                     $userId = $customerInfo['id'];
                     $post_data['userId'] = Constant::LKB_APPID.'_'.$userId;
                     $post_data['realname'] = $customerInfo['real_name'];
                     $post_data['idcard'] = $customerInfo['id_num'];
                     $post_data['teleno'] = $customerInfo['mobile'];
                     $res = $this->saveUserLKB($post_data);
                     Log::write("保存信息：".$res->result,Log::NOTICE);
                     if ($res->result) {//增加or更新用户信息成功
                         $arr['userId'] = Constant::LKB_APPID.'_'.$userId;
                         $arr['phone'] = $post_data['teleno'];
                         $arr['index'] = session('LKB_index');
                         $post_data = $this->postData($arr);
                         $url = "http://openapi.quantgroup.cn/LKBClient/openapi/phone/pt_ued_phone_img.json";
                         $res = json_decode($this->request_post($url, $post_data));
                         Log::write("验证是否需要验证码：".json_encode($res)."结果状态：".$res->status,Log::NOTICE);
                         if ($res->status) {//判断是否需要验证码成功
                             if ($res->isSms) {//需要发送短信
                                 $res4 = $this->mandateUser4($phone, 0);
                                 $index = session('LKB_index') + 1;
                                 session('LKB_index', $index);
              Log::write("验证是否需要验证码：".json_encode($res4)."结果状态：".$res4->status,Log::NOTICE);
                                 $type = 2;
                                 $ret = Constant::getReturn(Constant::SUCCESS);
                                 $ret['type'] = $type;
                                 $ret['imgcode'] =  '';
                                 $ret['in_need'] = '0';
                                 if (!$res4->status) {//短信发送失败
                                     $res4->errorcode = $this->ErrCode($res4->errorcode);
                                     $ret = (['code' => $res4->errorcode, 'msg' =>$res4->errorMsg]);
                                 }
                             } elseif ($res->imgUrl != '') {//图片验证码
                                 $imgcode = $res->imgUrl;
                                 $type = 1;
                                 $ret = Constant::getReturn(Constant::SUCCESS);
                                 $ret['type'] = $type;
                                 $ret['imgcode'] = $imgcode;
                                 $ret['in_need'] = '0';
                             } else {//只需要运营商密码
                                  $this->mandateUser2($phone,$server_pass);
                             }
                         } else {
                             $res->errorcode = $this->ErrCode($res->errorcode);
                             $ret = (['code' => $res->errorcode, 'msg' =>$res->errorMsg]);
                         }
                     } else {
                         $res->errorcode = $this->ErrCode($res->errorcode);
                         $ret = (['code' => $res->errorcode, 'msg' =>$res->errorMsg]);
                     }
                 }elseif(!empty($is_mandate) && $is_mandate['china_mobile'] == 1) {
                     //$ret = Constant::getReturn(Constant::SUCCESS);
                     BusinessException::throwException('该号码应经认证');
                     if($is_mandate['lianghua_pass']==0){
                  M('CustomerAuth')->where(['customer_id' => $is_mandate['customer_id']])->setField(['lianghua_pass'=>'1']);
                     }
                 }
             }

         }catch (BusinessException $e) {
             $ret = (['code' => $e->getCode(), 'msg' => $e->getMessage()]);
         }
         if($is_use==1 && $ret['code']!='101'){
             //return  $ret['imgcode'];
             return  $ret;
         }else{
             Response::format($ret);
             $this->ajaxReturn($ret);
         }

  }
    /*****************
     * 量化派用户授权2
     *****************/
    function mandateUser2($mobile='',$server=''){
        try {
            $phone = $mobile?$mobile:I('post.mobile', '', 'string');
            $server_pass = $server?$server:I("post.server_pass", '', 'string');//服务密码
            Log::write("授权认证2开始".$phone."参数：".$mobile."服务密码：".$server_pass,Log::NOTICE);
            if(!$phone || !$server_pass){
                BusinessException::throwException(Constant::INVALID_PARAMETER);
            }
            $type = I("post.type","","string");
            $smsCode = I("post.smsCode", '', 'string');//短信验证码
            $authCode = I("post.authCode", '', 'string');//图片验证码
            Log::write("授权认证2验证码".$smsCode."图片参数：".$authCode,Log::NOTICE);

            if($type==1 && !$authCode){
                BusinessException::throwException(Constant::INVALID_PARAMETER);
            }elseif($type==2 && !$smsCode){
                BusinessException::throwException(Constant::INVALID_PARAMETER);
            }
            $customerInfo = M('Customer')->where(['mobile' => $phone])->find();
            $arr['userId'] = Constant::LKB_APPID.'_'.$customerInfo['id'];
            $arr['phone'] = $phone;
            $arr['password'] = $server_pass;
            $arr['smsCode'] = $smsCode;
            $arr['authCode'] = $authCode;
            $post_data = $this->postData($arr);
            $url = "http://openapi.quantgroup.cn/LKBClient/openapi/phone/pt_ued_phone_login.json";
            $res = json_decode($this->request_post($url, $post_data));
            Log::write("授权认证2结果".json_encode($res),Log::NOTICE);
            if ($res->status) {
                if ($res->result) {//认证成功，结束
                  M('CustomerAuth')->where(['customer_id' => $customerInfo['id']])->setField(['china_mobile' => '1','lianghua_pass'=>'1']);
                    $this->getReportJson($phone);
                    $type = 0;
                    $ret = Constant::getReturn(Constant::SUCCESS);
                    $ret['type'] = $type;
                    $ret['imgcode'] = '';
                }else{
                    if($res->imgUrl=='getImg'){//获取图片验证码--3、
                        $type = 1;
                        $res3 = $this->mandateUser3($phone,session('LKB_index'));
                        $index = session('LKB_index') + 1;
                        session('LKB_index',$index);
                        if($res3->status){
                            $imgcode = $res3->imgUrl;
                            $ret = Constant::getReturn(Constant::SUCCESS);
                            $ret['type'] = $type;
                            $ret['in_need'] = '1';
                            $ret['imgcode'] = isset($imgcode)?$imgcode:'';
                        }else{
                            $res3->errorcode = $this->ErrCode($res3->errorcode);
                            $ret = (['code' => $res3->errorcode, 'msg' =>$res3->errorMsg]);
                        }
                    }elseif($res->authCheck){//获取身份证号码和真实姓名--4、获取短信验证码
                        $type = 2;
                        $res4 = $this->mandateUser4($phone,1);
                        $index = session('LKB_index') + 1;
                        session('LKB_index',$index);
                        $ret = Constant::getReturn(Constant::SUCCESS);
                        $ret['type'] = $type;
                        $ret['imgcode'] = '';
                        $ret['in_need'] = '1';
                        if(!$res4->status){
                            $res4->errorcode = $this->ErrCode($res4->errorcode);
                            $ret = (['code' => $res4->errorcode, 'msg' =>$res4->errorMsg]);
                        }
                    }else{//直接获取短信验证码--4、
                        $type = 2;
                        $res4 = $this->mandateUser4($phone,0);
                        $index = session('LKB_index') + 1;
                        session('LKB_index',$index);
                        $ret = Constant::getReturn(Constant::SUCCESS);
                        $ret['type'] = $type;
                        $ret['imgcode'] = '';
                        $ret['in_need'] = '1';
                        if(!$res4->status){
                            $res4->errorcode = $this->ErrCode($res4->errorcode);
                            $ret = (['code' => $res4->errorcode, 'msg' =>$res4->errorMsg]);
                        }
                    }
                }

            } else {//失败
                Log::write("授权认证2结果失败".$res->errorcode,Log::NOTICE);
                $res->errorcode = $this->ErrCode($res->errorcode);
                $imgcode  = '';
                if($res->errorcode==20012){
                    if($type==1){//调接口3
                        session('u2_msg',$res->errorMsg);
                        $index = session('LKB_index')?session('LKB_index'):1;
                        session('LKB_index',$index+1);
                        $res1 = $this->mandateUser1(0,1);
                        $imgcode = $res1['imgcode']?$res1['imgcode']:'';
                    }elseif($type==2){//调接口4
                        $this->mandateUser4($phone, 0);
                        $index = session('LKB_index') + 1;
                        session('LKB_index', $index);
                    }
                }
                $ret = (['code' => $res->errorcode, 'msg' =>$res->errorMsg ,'type'=>$type, 'imgcode'=>$imgcode]);

            }
        }catch (BusinessException $e) {
            $ret = (['code' => $e->getCode(), 'msg' => $e->getMessage()]);
        }
        Response::format($ret);
        $this->ajaxReturn($ret);
    }
    /*****************
     * 量化派用户授权3
     ****************/
    function mandateUser3($phone,$index){
        Log::write("授权认证3开始".$phone,Log::NOTICE);
        $url = "http://openapi.quantgroup.cn/LKBClient/openapi/phone/pt_ued_phone_img2.json";
        $arr['index'] = $index;
        $customerInfo = M('Customer')->where(['mobile' => $phone])->find();
        $arr['userId'] = Constant::LKB_APPID.'_'.$customerInfo['id'];
        $arr['phone'] = $phone;
        $post_data = $this->postData($arr);
        $res = json_decode($this->request_post($url,$post_data));
        Log::write("授权认证3结果".json_encode($res),Log::NOTICE);
        return $res;
    }
    /****************
     * 量化派用户授权4
     *****************/
    function mandateUser4($phone,$real=0){
        Log::write("授权认证4开始".$phone,Log::NOTICE);

        $customerInfo = M('Customer')->where(['mobile' => $phone])->find();
        $arr['userId'] = Constant::LKB_APPID.'_'.$customerInfo['id'];
        $arr['phone'] = $phone;
        if($real){//获取身份账号吗和真实姓名
            $arr['idCard'] = $customerInfo['id_num'];
            $arr['realName'] = $customerInfo['real_name'];
        }
        $post_data = $this->postData($arr);
        $url = "http://openapi.quantgroup.cn/LKBClient/openapi/phone/pt_ued_phone_sms.json";
        $res = json_decode($this->request_post($url,$post_data));
        Log::write("授权认证4结束".json_encode($res),Log::NOTICE);

        return $res;
    }
    /******************
     * 量化派用户授权5
     *****************/
    function mandateUser5(){
        try {
            $phone = I("post.mobile","","string");
            $smsCode = I("post.smsCode","","string");//短信验证码
            $authCode = I("post.authCode","","string");//图片验证码
            $type = I("post.type","","string");
            Log::write("授权认证5开始".$phone,Log::NOTICE);
            if(!$phone || !$smsCode){
                BusinessException::throwException(Constant::INVALID_PARAMETER);
            }
            if($type==1 && !$authCode){
                BusinessException::throwException(Constant::INVALID_PARAMETER);
            }
            $customerInfo = M('Customer')->where(['mobile' => $phone])->find();
            $arr['userId'] = Constant::LKB_APPID.'_'.$customerInfo['id'];
            $arr['phone'] = $phone;
            $arr['smsCode'] = $smsCode;
            $arr['authCode'] = $authCode;
            $post_data = $this->postData($arr);
            $url = "http://openapi.quantgroup.cn/LKBClient/openapi/phone/pt_ued_phone_service.json";
            $res = json_decode($this->request_post($url, $post_data));
            Log::write("授权认证5结果".json_encode($res),Log::NOTICE);
            if($res->status){//成功
                M('CustomerAuth')->where(['customer_id' => $customerInfo['id']])->setField(['china_mobile' => '1','lianghua_pass'=>'1']);
                //$this->getReportJson($phone);
                $ret = Constant::getReturn(Constant::SUCCESS);
            }elseif(!$res->status && $res->errorcode!=0){
                $ret = (['code' => '101', 'msg' =>'失败']);
            }
            else{//失败
                $res->errorcode = $this->ErrCode($res->errorcode);
                $imgcode = '';
                if($res->errorcode==20012){
                    $index = session('LKB_index')?session('LKB_index'):1;
                    if($type==1){//调接口3
                        $res1 = $this->mandateUser1(0,1);
                        $imgcode = $res1['imgcode']?$res1['imgcode']:'';
                    }else{
                        $this->mandateUser4($phone, 0);
                        $index = $index + 1;
                        session('LKB_index', $index);
                    }
                }
                $ret = (['code' => $res->errorcode, 'msg' =>$res->errorMsg,'type'=>$type,'imgcode'=>$imgcode]);
            }
        }catch (BusinessException $e) {
            $ret = (['code' => $e->getCode(), 'msg' => $e->getMessage()]);
        }
        Response::format($ret);
        $this->ajaxReturn($ret);
    }

    /*********
     * 量化派  校验错误码
     *******/
     function ErrCode($err_code){
         if($err_code==10001){
             $err_code1 = 101;
         }elseif($err_code==10008){
             $err_code1 = 101;
         }elseif ($err_code==10009){
             $err_code1 = 101;
         }elseif ($err_code==10011){
             $err_code1 = 101;
         }elseif($err_code==0){
             $err_code1 = 20012;
         }else{
             $err_code1 = $err_code;
         }
        return $err_code1;
     }



    /********************
     * 量化派   抓取数据源
     ******************/

    function getReport(){
        try {
            $phone = I("post.mobile","","string");
            Log::write("抓取报告开始：".$phone,Log::NOTICE);
            $customerInfo = M('Customer')->where(['mobile' => $phone])->find();
            $is_mandate = M("CustomerAuth")->where("customer_id =" . $customerInfo['id'])->find();
            if (empty($is_mandate)) {
                BusinessException::throwException(Constant::ID_NUM_NO_AUTHED);
            } elseif (!empty($is_mandate) && $is_mandate['china_mobile'] == 0) {
                BusinessException::throwException('请进行运营商认证');
            }
            $lkb_status = $this->LKBStatus($phone);
            if($lkb_status->status) {
                $arr['userId'] = Constant::LKB_APPID . '_' . $customerInfo['id'];
                $post_data = $this->postData($arr);
                $url = "http://openapi.quantgroup.cn/LKBClient/openapi/report/detail.json";
                $res = $this->request_post($url, $post_data);
                $info = json_decode($res);
                if ($info->errorcode == 0) {
                    $ret = Constant::getReturn(Constant::SUCCESS);
                    $ret['data'] = $res;
                } elseif ($info->errorcode == -1) {
                    $res->errorcode = $this->ErrCode($res->errorcode);
                    $ret = (['code' => $res->errorcode, 'msg' => '报告数据为空']);
                } else {
                    $res->errorcode = $this->ErrCode($res->errorcode);
                    $ret = (['code' => $res->errorcode, 'msg' => $res->errorMsg]);
                }
            }else{
                $ret = (['code' => '101', 'msg' => '提取数据状态失败']);
            }
        }catch (BusinessException $e) {
            $ret = (['code' => $e->getCode(), 'msg' => $e->getMessage()]);
        }
        Response::format($ret);
        $this->ajaxReturn($ret);
    }
   /****************
    * 量化派   查询抓取状态
    ***************/
     function LKBStatus($mobile=''){
         try {
             $phone = $mobile?$mobile:I("post.mobile", "", "string");
             $userSource = "YUNYINGSHANG";
             if (!$phone) {
                 BusinessException::throwException(Constant::INVALID_PARAMETER);
             }
             $customerInfo = M('Customer')->where(['mobile' => $phone])->find();
             $arr['userId'] = Constant::LKB_APPID . '_' . $customerInfo['id'];
             $arr['phone'] = $phone;
             $arr['userSource'] = $userSource;
             $post_data = $this->postData($arr);
             $url = "http://openapi.quantgroup.cn/LKBClient/openapi/report/checkstatus.json";
             $res = json_decode($this->request_post($url, $post_data));
             Log::write("状态结果:".$res->status,Log::NOTICE);
             if($res->status){
                 $ret = Constant::getReturn(Constant::SUCCESS);
             }else{
                 $ret = (['code' => '101', 'msg' => '抓取失败']);
             }
         }catch (BusinessException $e) {
             $ret = (['code' => $e->getCode(), 'msg' => $e->getMessage()]);
         }
         if($mobile=='') {
             Response::format($ret);
             $this->ajaxReturn($ret);
         }else{
             return $res;
         }
    }
    /***************
     * 量化派  提交信用报告
     ***************/
     function makeReport($mobile=''){
         $phone = $mobile?$mobile:I("post.mobile", "", "string");
         $customerInfo = M('Customer')->where(['mobile' => $phone])->find();
         $lkb_status = $this->LKBStatus($phone);
         if($lkb_status->status) {//抓取数据源成功
             $arr['userId'] = Constant::LKB_APPID . '_' . $customerInfo['id'];
             $post_data = $this->postData($arr);
             $url = "http://openapi.quantgroup.cn/LKBClient/openapi/newReport/makeReport.json";
             $res = json_decode($this->request_post($url, $post_data));
             Log::write("提交报告状态：".$res->status,Log::NOTICE);
             if($res->status==1){//成功
                 $ret = (['code' => '0', 'msg' => '提取报告提交完成']);
             }else{
                 BusinessException::throwException(Constant::CUSTOMER_NOT_FOUND);
             }
         }else{
             $ret = (['code' => '101', 'msg' => '提取数据状态失败']);
         }
         if($mobile=='') {
             Response::format($ret);
             $this->ajaxReturn($ret);
         }else{
             return $res;
         }
     }
    /*************
     * 量化派   查看报告 自动生成pdf文档
     ***************/
     function checkReport(){
         $phone = I("post.mobile", "", "string");
         $status = $this->makeReport($phone);
         if($status->status) {
             $customerInfo = M('Customer')->where(['mobile' => $phone])->find();
             $arr['userId'] = Constant::LKB_APPID . '_' . $customerInfo['id'];
             $post_data = $this->postData($arr);
             $url = "http://openapi.quantgroup.cn/LKBClient/openapi/newReport/checkReport.json";
             $res = json_decode($this->request_post($url, $post_data));
             Log::write("查看报告状态：" . $res->status, Log::NOTICE);
             if ($res->status == 1) {//1:报告生成成功;
                 $ret = Constant::getReturn(Constant::SUCCESS);
                 $ret['data'] = $res->url;
             } elseif ($res->status == 0) {//0:报告正在生成中,
                 $ret = (['code' => '0', 'msg' => '报告正在生成中,再等一下！']);
             } elseif ($res->status == -3) {// -3:在t_report没有记录,
                 $ret = (['code' => '101', 'msg' => '没有报告记录']);
             } else {//-1:用户Id为空, -2:该用户为空,
                 $ret = (['code' => '101', 'msg' => '请确认用户状态']);
             }
         }else{
             $ret = (['code' => '101', 'msg' => '生成报告失败']);
         }
         Response::format($ret);
         $this->ajaxReturn($ret);
     }
     /**********************
      * 量化派  查看报告JSON数据
      *********************/

      function  getReportJson($mobile=''){
          $phone = $mobile?$mobile:I("post.mobile", "", "string");
          $status = $this->LKBStatus($phone);
          if($status->status==1) {
              $this->makeReport($phone);
              if($res->status==1){//成功

              $customerInfo = M('Customer')->where(['mobile' => $phone])->find();
              $arr['userId'] = Constant::LKB_APPID . '_' . $customerInfo['id'];
              $post_data = $this->postData($arr);
              $url = "http://openapi.quantgroup.cn/LKBClient/openapi/report/getReportJson.json";
              $res = json_decode($this->request_post($url, $post_data));
              if($mobile=='') {
                  //1获取到数据 0用户不存在 -1报告不存在 -2报告正在生成
                  if ($res->status == 1) {
                      $ret = Constant::getReturn(Constant::SUCCESS);
                      $ret['data'] = $res->json;
                  } elseif ($res->status == 0) {
                      BusinessException::throwException("用户未通过量化认证");

                  } elseif ($res->status == -1) {
                      BusinessException::throwException("报告不存在");

                  } elseif ($res->status == -2) {
                      BusinessException::throwException("报告正在生成，再等一分钟。。！");
                  }
                  Response::format($ret);
                  $this->ajaxReturn($ret);
              }
           }else{
             BusinessException::throwException("提交报告失败");
           }
          }elseif($status->status==0){
              if($mobile=='') {
                  BusinessException::throwException("数据正在抓取中。。");
              }
          }
      }






}
